class Solution:
    def minimumMountainRemovals(self, nums: list) -> int:
        dpl = [1 for _ in range(len(nums))]
        dpr = [1 for _ in range(len(nums))]
        for i in range(1, len(nums)):
            for j in range(i):
                if nums[i] > nums[j]:
                    dpl[i] = max(dpl[i], dpl[j] + 1)
        for i in range(len(nums) - 2, -1, -1):
            for j in range(len(nums) - 1, i, -1):
                if nums[i] > nums[j]:
                    dpr[i] = max(dpr[i], dpr[j] + 1)
        maxlen = 0
        for i in range(1, len(nums) - 1):
            if dpl[i] == 1 or dpr[i] == 1:
                continue
            curlen = dpl[i] + dpr[i] - 1
            maxlen = max(maxlen, curlen)

        return len(nums) - maxlen
